package main

import (
	"bufio"
	"encoding/json"
	"log"
	"net"

	aop "gitee.com/jnshao/go-start/pattern/ch04/aop/core"
)

func main() {
	conn, err := net.Dial("tcp", ":8080")
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()
	reader := bufio.NewReader(conn)
	var contentBytes []byte
	bytes := make([]byte, 8)
	for {
		n, _ := reader.Read(bytes)
		if n == 0 {
			break
		}
		contentBytes = append(contentBytes, bytes[:n]...)
	}
	content := &aop.Content{}
	err = json.Unmarshal(contentBytes, content)
	if err != nil {
		log.Printf("json err:%v", err)
	}
	log.Printf("result:%+v", content)
}
